package com.example.googlemapdrawroutelast.task;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import android.content.Context;
import android.os.AsyncTask;
import android.view.View;
import android.widget.Toast;

import com.example.googlemapdrawroutelast.UrlClass;

public class DropRouteTask extends AsyncTask<Integer, Void, Integer> {

	private View view;
	private Context context;

	public DropRouteTask(View view, Context context) {
		super();
		this.view = view;
		this.context = context;
	}

	@Override
	protected Integer doInBackground(Integer... params) {
		try {
			
			
			// Log.v("DELETETask", "started");
			String strUrl = "http://" + UrlClass.getUrl() + "/v1/delRoute/"
					+ params[0].toString() + "/" + params[1].toString();
			URL url = new URL(strUrl);
			HttpURLConnection connection = (HttpURLConnection) url
					.openConnection();
			connection.setConnectTimeout(15000);
			connection.setReadTimeout(15000);
			connection.setRequestMethod("DELETE");

			/*
			 * if (id_route != 0) {
			 * connection.setRequestProperty("Authorization", "poprawne"); }
			 */
			connection.setDoOutput(true);

			/*
			 * DataOutputStream dataOutputStream = new DataOutputStream(
			 * connection.getOutputStream());
			 * dataOutputStream.writeBytes("id_route" + id_route);
			 * dataOutputStream.flush(); dataOutputStream.close();
			 */

			connection.connect();

			InputStream iStream = connection.getInputStream();
			BufferedReader reader = new BufferedReader(
					new InputStreamReader(iStream));

			StringBuffer sb = new StringBuffer();
			String line = "";

			while ((line = reader.readLine()) != null) {
				sb.append(line);
			}

			reader.close();
			iStream.close();
			 return null;
			

		} catch (Exception e) {
			e.getMessage();
		}
		return null;
	}
	@Override
	protected void onPostExecute(Integer integer)
	{
 		Toast.makeText(context, "Trasa zostala usnieta", Toast.LENGTH_LONG).show();
	}
	
	

}
